local wen__yingying = fk.CreateSkill {
  name = "wen__yingying",
}

Fk:loadTranslationTable{
  ["wen__yingying"] = "影映",
  [":wen__yingying"] = "出牌阶段，你可以改为<a href='premeditate_href'>“蓄谋”</a>一次，然后若你场上的蓄谋牌少于三张，你摸一张牌并重复此流程。",

  ["#wen__yingying-invoke"] = "影映：是否改为重复“蓄谋-摸牌”流程？",
}

local U = require "packages.utility.utility"

wen__yingying:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    return target == player
    and player:hasSkill(wen__yingying.name)
    and player.phase == Player.Play
    and not player:isKongcheng()
    and not table.contains(player.sealedSlots, Player.JudgeSlot)
  end,

  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = wen__yingying.name,
      cancelable = true,
      prompt = "#wen__yingying-invoke"
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,

  on_use = function(self, event, target, player, data)
    local room = player.room
    U.premeditate(player, event:getCostData(self).cards, wen__yingying.name)
    local cards = table.filter(player:getCardIds("j"), function (id)
      return player:getVirtualEquip(id) and player:getVirtualEquip(id).name == "premeditate"
    end)

    while not player.dead and not table.contains(player.sealedSlots, Player.JudgeSlot) and #cards < 3 do
      player:drawCards(1, wen__yingying.name)
      local card = room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = wen__yingying.name,
        cancelable = false,
        prompt = "#wen__yingying-invoke",
      })
      if #card > 0 then
        U.premeditate(player, card, wen__yingying.name, player)
        cards = table.filter(player:getCardIds("j"), function (id)
          return player:getVirtualEquip(id) and player:getVirtualEquip(id).name == "premeditate"
        end)
      else
        return
      end
    end
    player:endPlayPhase()
  end,
})

return wen__yingying